/* -------------------------------------------------------------------------- *
   TestWinUnit - Maria Blees (maria.blees@microsoft.com)

   File: EnvironmentTest.cpp
   Contains tests for the Environment class found in WinUnit.h.
 * -------------------------------------------------------------------------- */
#include "WinUnit.h"

FIXTURE(EnvironmentTest);

SETUP(EnvironmentTest)
{
    _wputenv_s(L"Foo", L"Bar");
}

TEARDOWN(EnvironmentTest)
{
    // Get rid of the Foo environment variable
    _wputenv_s(L"Foo", L"");
}

BEGIN_TESTF(EnvironmentGetVarSucceedsWithBufferSizeNPlus1, EnvironmentTest)
{
    TCHAR buffer[4] = _T("");
    WIN_ASSERT_TRUE(
        WinUnit::Environment::GetVariable(_T("Foo"), 
        buffer,
        ARRAYSIZE(buffer),
        NULL));
}
END_TESTF

BEGIN_TESTF(EnvironmentGetVarFailsWithBufferSizeN, EnvironmentTest)
{
    TCHAR buffer[3] = _T("");
    DWORD sizeNeeded = 0;
    WIN_ASSERT_FALSE(
        WinUnit::Environment::GetVariable(_T("Foo"), 
        buffer,
        ARRAYSIZE(buffer),
        &sizeNeeded));

    WIN_ASSERT_EQUAL(4U, sizeNeeded);
}
END_TESTF

BEGIN_TEST(EnvironmentGetVarFailsWithVarNotFound)
{
    TCHAR buffer[10] = _T("");
    WIN_ASSERT_FALSE(
        WinUnit::Environment::GetVariable(_T("Foo"), 
        buffer,
        ARRAYSIZE(buffer),
        NULL));
}
END_TEST
